import { PropsWithChildren, useEffect } from "react";
import { Provider } from "react-redux";
import store from "./store/index";
import { setUserInfo } from "./store/reducers/userInfo";

import "./app.scss";
import Taro from "@tarojs/taro";

function App({ children }: PropsWithChildren<any>) {
  useEffect(() => {
    const token = Taro.getStorageSync("token");
    const userInfo = Taro.getStorageSync("userInfo");
    const storeToken = store.getState().userInfo.token;
    if (token && !storeToken) {
      console.log(userInfo.shopOwnerInfo);
      store.dispatch(setUserInfo(userInfo));
    }
  }, []);
  // children 是将要会渲染的页面
  return <Provider store={store}>{children}</Provider>;
}

export default App;
